package QuanLyKhachHang;

import KetNoiSQL.KetNoiSQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class KhachHang {

    private int maKhachHang;
    private String tenKhachHang;
    private String loaiKhachHang;
    private String soDT;
    private String fax;
    private String email;
    private String diaChi;
    private String quanHe;

    public int getMaKhachHang() {
        return maKhachHang;
    }

    public void setMaKhachHang(int maKhachHang) {
        this.maKhachHang = maKhachHang;
    }

    public String getTenKhachHang() {
        return tenKhachHang;
    }

    public void setTenKhachHang(String tenKhachHang) {
        this.tenKhachHang = tenKhachHang;
    }

    public String getLoaiKhachHang() {
        return loaiKhachHang;
    }

    public void setLoaiKhachHang(String loaiKhachHang) {
        this.loaiKhachHang = loaiKhachHang;
    }

    public String getSoDT() {
        return soDT;
    }

    public void setSoDT(String soDT) {
        this.soDT = soDT;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getQuanHe() {
        return quanHe;
    }

    public void setQuanHe(String quanHe) {
        this.quanHe = quanHe;
    }

    //Xem danh sách khách hàng
    public static Vector xemDanhSachKhachHang() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemKhachHang");
            while (rs.next()) {
                KhachHang kh = new KhachHang();

                kh.maKhachHang = rs.getInt(1);
                kh.tenKhachHang = rs.getString(2);
                kh.loaiKhachHang = rs.getString(3);
                kh.soDT = rs.getString(4);
                kh.fax = rs.getString(5);
                kh.email = rs.getString(6);
                kh.diaChi = rs.getString(7);
                kh.quanHe = rs.getString(8);

                v.add(kh);
            }
        } catch (SQLException ex) {
        }
        return v;
    }

    //Thêm Khách hàng
    public static int themKhachHang(KhachHang kh) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(kh.tenKhachHang);
            dsThamSo.add(kh.loaiKhachHang);
            dsThamSo.add(kh.soDT);
            dsThamSo.add(kh.fax);
            dsThamSo.add(kh.email);
            dsThamSo.add(kh.diaChi);
            dsThamSo.add(kh.quanHe);

            i = KetNoiSQL.thucHienCapNhat("spThemKhachHang", dsThamSo);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return i;
    }

    //Cập nhật khách hàng
    public static int capNhatKhachHang(KhachHang kh) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(kh.maKhachHang);
            dsThamSo.add(kh.tenKhachHang);
            dsThamSo.add(kh.loaiKhachHang);
            dsThamSo.add(kh.soDT);
            dsThamSo.add(kh.fax);
            dsThamSo.add(kh.email);
            dsThamSo.add(kh.diaChi);
            dsThamSo.add(kh.quanHe);
            i = KetNoiSQL.thucHienCapNhat("spCNKhachHang", dsThamSo);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    //Xóa khách hàng
    public static int xoaKhachHang(String ten) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(ten);
            i = KetNoiSQL.thucHienCapNhat("spXoaKhachHang", dsThamSo);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    //Tìm kiếm thuốc
    public static Vector timKiem(String tenSP, Vector timKiem) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan(tenSP, timKiem);
            while (rs.next()) {
                KhachHang tkkh = new KhachHang();
                tkkh.maKhachHang = rs.getInt(1);
                tkkh.tenKhachHang = rs.getString(2);
                tkkh.loaiKhachHang = rs.getString(3);
                tkkh.soDT = rs.getString(4);
                tkkh.fax = rs.getString(5);
                tkkh.email = rs.getString(6);
                tkkh.diaChi = rs.getString(7);
                tkkh.quanHe = rs.getString(8);
                v.add(tkkh);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;

    }
}
